import {defHttp} from '/@/utils/http/axios';
import {DictionaryInfo, DictionaryPageListGetResultModel, DictionaryPageParams} from "./model/dictionaryModel";
import {BasicPageSearchParams, CheckExistParams} from "/@/api/model/baseModel";

enum Api {
  DictionaryPageList = '/base/dictionary/list',
  SaveOrUpdate = '/base/dictionary/saveOrUpdate',
  Delete = '/base/dictionary/del/',
  CheckEntityExist = '/base/dictionary/checkEntityExist',
  getList = '/base/dictionary/getList/',
  ProjectTypeList = '/base/dictionary/project_type',
}

export const dictionaryPageList = (params: DictionaryPageParams) =>{
  const query = params&&{pageNum: params.pageNum, pageSize: params.pageSize};
  let entity = params||{};
  if(entity){
    delete entity['pageNum'];
    delete entity['pageSize'];
  }
  const queryParam = {query, entity} as BasicPageSearchParams<DictionaryPageParams>;
  return defHttp.post<DictionaryPageListGetResultModel>({ url: Api.DictionaryPageList,  params: queryParam });
}

export const saveOrUpdate = (params?: DictionaryInfo) =>
  defHttp.post<DictionaryInfo>({url: Api.SaveOrUpdate, params});

export const deleteByIds = (id: string) =>
  defHttp.post<DictionaryInfo>({url: Api.Delete + id});

export const getList = (name: string) =>{
  return defHttp.get<any>({ url: Api.getList + name});
}

export const ProjectTypeList = () =>{
  return defHttp.get<any>({ url: Api.ProjectTypeList });
}
